package name.jiaosha.air.company.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import name.jiaosha.air.OperateTip;
import name.jiaosha.air.company.domain.Company;
import name.jiaosha.air.company.domain.Department;
import name.jiaosha.air.company.domain.Employee;
import name.jiaosha.air.company.service.ICompanyService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("employeeController")
public class EmployeeController {

	@Autowired
	private ICompanyService companyService;

	public List<Employee> getMyEmployeeList() {

		return companyService.getEmployeeByComId(1);

	}

	public List<Map<String, Object>> getEeployeeById(int id) {

		List<Map<String, Object>> list = null;
		list = new ArrayList<Map<String, Object>>();
		Map<String, Object> m = new HashMap<String, Object>();

		Employee employee = companyService.getEmployeeById(id);
		employee.getDepartment();

		m.put("employee", employee);
		list.add(m);
		m = null;
		List<Department> departments = companyService
				.getDepartmentByComId(employee.getCompany().getId());
		m = new HashMap<String, Object>();
		m.put("departments", departments);

		list.add(m);
		return list;
	}

	public OperateTip create(Employee employee) {
		Company company = companyService.getCompanyById(1);
		Department department = companyService.getDepartmentById(1);

		employee.setCompany(company);
		employee.setDepartment(department);
		companyService.createEmployee(employee);

		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}

	public OperateTip update(Employee employee) {

		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}

}
